<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Created by PhpStorm.
 * User: jinzhao
 * Date: 16-8-3
 * Time: 下午7:13
 */
class Login_model extends CI_Model{
    
    public function create_captcha()
    {
        $this->load->helper('captcha');
        $this->load->helper('url');
        $param =  array(
            'img_path' => dirname(BASEPATH) . '/captcha/',
            'img_url' => base_url('captcha'). '/',
            'expiration' => 1,
            'img_width' => 80,
            'img_height' => 25
        );
        $captcha = create_captcha($param);
        $this->session->set_userdata('captcha', $captcha['word']);
        return $captcha;
    }
    
    
    public function is_valid_captcha($captcha)
    {
        if (strtoupper($captcha) !=
            strtoupper($this->session->userdata('captcha'))){
            return false;
        }
        return true;
    }
    public function find($email, $password)
    {
        $result = $this->db->where(array('email' => $email, 'password' => $password))->from('user')->get()->result_array();
        if (count($result) > 0){
            return true;
        }
        return false;
    }
}